import pymysql
from flask import Flask, render_template

# Connect to the MySQL database
conn = pymysql.connect(
    host="localhost",
    user="root",
    password="123456",
    database="kq"
)

# Create a cursor object to execute SQL queries
cursor = conn.cursor()

# Fetch the top six students based on GPA (Content-Based Filtering)
cursor.execute("SELECT name FROM student ORDER BY gpa DESC LIMIT 6")
top_content_based_students = cursor.fetchall()

# Fetch the top six students based on collaborative filtering (Collaborative Filtering)
# (Assuming the collaborative filtering algorithm is implemented separately)
# Replace the recommendation code below with the appropriate collaborative filtering method

top_collaborative_filtering_students = []  # Replace this line with the actual collaborative filtering recommendation code

# Render the template with data
app = Flask(__name__)

@app.route('/')
def display_recommendations():
    return render_template('recommendations.html', 
                           content_based_students=top_content_based_students, 
                           collaborative_filtering_students=top_collaborative_filtering_students)

if __name__ == '__main__':
    app.run()

# Close the cursor and database connection
cursor.close()
conn.close()
